class Admin < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :timeoutable,
         :rememberable, :trackable, :validatable

  belongs_to :role
  delegate :permissions, to: :role

  def name_or_email
    name or email
  end

  def can?(action)
    return false unless role
    permissions.exists?(action: action)
  end
end
